package com.yonyou.lxp.xutils3test.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by liuxiaopeng on 16/3/14.
 */
public abstract class RecyclerViewAdapter<T> extends BaseAdapter {
    private Context mContext;
    private int layoutId;
    private List<T> list;

    public RecyclerViewAdapter(Context mContext, List<T> list, int mode, int layoutId) {
        super(mContext, mode);
        this.mContext = mContext;
        this.list = list;
        this.layoutId = layoutId;
    }

    public abstract void convert(ViewHolder helper, T item, int position);

    @Override
    protected ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        final ViewHolder viewHolder = ViewHolder.get(mContext,null,parent, layoutId );
        return viewHolder;
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder h, int position) {
        convert((ViewHolder) h, list.get(position), position);
    }

}
